﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Packaging;
using System.IO;
using System.Xml;

namespace CopySniffer.FileLoad.Docx
{
    public class DocxFileLoader : IFileLoader
    {
        private readonly string[] supportedExtensions = { "docx" };

        #region IFileLoader Members

        public IEnumerable<string> SupportedExtensions
        {
            get { return supportedExtensions; }
        }

        public string TypeAlias
        {
            get { return "Microsoft Word 2007"; }
        }

        public string LoadFile(string fileName)
        {
            Package package = ZipPackage.Open(fileName);
            //word/document.xml
            PackagePart part = package.GetPart(new Uri(@"/word/document.xml", UriKind.Relative));
            Stream contentsStream = part.GetStream();
            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(contentsStream);
            return xDoc.InnerText;
        }

        #endregion
    }
}
